home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / whdload / rawdic17.lha / Examples / Virus.islave.asm < prev    next >
Assembly Source File  |  1999-03-02  |  2KB  |  118 lines

  1.  
  2.     ; Virus imager
  3.  
  4.     ; A track contains $1800 bytes of data.
  5.  
  6.     ; track format description:
  7.  
  8.     ; sync ($8944)
  9.     ; 1 unused byte
  10.     ; $1800 bytes data
  11.     ; 1 word checksum
  12.  
  13.     ; The checksum test is quite strange, a CRC16 calculation is done
  14.     ; which always leads to 0 when everything went ok.
  15.     ; Part of the CRC16 calculation are also 3 sync signal words and
  16.     ; the unused byte following the sync, and ofcourse the checksum.
  17.  
  18.     ; The MFM decoding is done by skipping all odd bits in the bitstream.
  19.  
  20.     ; Similar formats: Starglider 2 (uses the same CRC16 method)
  21.  
  22.         incdir    Includes:
  23.         include    RawDIC.i
  24.  
  25.         SLAVE_HEADER
  26.         dc.b    1    ; Slave version
  27.         dc.b    0    ; Slave flags
  28.         dc.l    DSK_1    ; Pointer to the first disk structure
  29.         dc.l    Text    ; Pointer to the text displayed in the imager window
  30.  
  31.         dc.b    "$VER:"
  32. Text:        dc.b    "Virus imager V1.0",10,"by John Selck on 02.03.1999",0
  33.         cnop    0,4
  34.  
  35. DSK_1:        dc.l    0        ; Pointer to next disk structure
  36.         dc.w    1        ; Disk structure version
  37.         dc.w    DFLG_SINGLESIDE    ; Disk flags
  38.         dc.l    TL_1        ; List of tracks which contain data
  39.         dc.l    0        ; UNUSED, ALWAYS SET TO 0!
  40.         dc.l    FL_DISKIMAGE    ; List of files to be saved
  41.         dc.l    0        ; Table of certain tracks with CRC values
  42.         dc.l    0        ; Alternative disk structure, if CRC failed
  43.         dc.l    Init        ; Called before a disk is read
  44.         dc.l    0        ; Called after a disk has been read
  45.  
  46. TL_1:        TLENTRY    40,69,$1800,$8944,DMFM_Virus    ; actually track 1 to 70, but only tracks 40 to 69 contain relevant data
  47.         TLEND
  48.  
  49. DMFM_Virus:
  50.         lea    CRC_table,a2    ; initialise registers for CalcCRC16
  51.         moveq    #0,d1
  52.         moveq    #-1,d2
  53.         moveq    #-1,d3
  54.  
  55.         subq.l    #2*3,a0        ; 3 syncwords needed for CRC calculation
  56.  
  57.         moveq    #3,d6
  58. .l0        bsr.b    NextByte
  59.         bsr.b    CalcCRC16
  60.         dbra    d6,.l0
  61.  
  62.         move.w    #$17ff,d6
  63. .l1        bsr.b    NextByte    ; decode data
  64.         bsr.b    CalcCRC16
  65.         move.b    d0,(a1)+
  66.         dbra    d6,.l1
  67.  
  68.         moveq    #1,d6
  69. .l2        bsr.b    NextByte
  70.         bsr.b    CalcCRC16
  71.         dbra    d6,.l2
  72.  
  73.         or.b    d2,d3
  74.         bne.b    .error
  75.  
  76.         moveq    #IERR_OK,d0
  77.         rts
  78. .error        moveq    #IERR_CHECKSUM,d0
  79.         rts
  80.  
  81. NextByte:    move.w    (a0)+,d0
  82.         BITSKIP_B d0
  83.         rts
  84. CalcCRC16:
  85.         move.b    d0,d1
  86.         eor.b    d2,d1
  87.         lea    (a2,d1.w),a3
  88.         move.b    (a3),d2
  89.         eor.b    d3,d2
  90.         move.b    $0100(a3),d3
  91.         rts
  92.  
  93. Init:        ; initialisation of the CRC table.
  94.  
  95.         lea    CRC_table,a0
  96.         moveq    #0,d1
  97. .l1        moveq    #0,d2
  98.         move.b    d1,d2
  99.         lsl.w    #8,d2
  100.         moveq    #7,d0
  101. .l0        add.w    d2,d2
  102.         bcc.b    .s0
  103.         eor.w    #$1021,d2    ; $1021 = standard CRC16 value
  104. .s0        dbra    d0,.l0
  105.         move.b    d2,$0100(a0)
  106.         lsr.w    #8,d2
  107.         move.b    d2,(a0)+
  108.         addq.b    #1,d1
  109.         bne.b    .l1
  110.  
  111.         moveq    #IERR_OK,d0
  112.         rts
  113.  
  114.     section    "BSS",bss
  115.  
  116. CRC_table:    ds.b    $200
  117.  
  118.